<template>
    <div class="content">
        <van-cell-group>
            <van-field v-model="manager_username" label="加盟商用户名" placeholder="分配的加盟商用户名" />
        </van-cell-group>
        <div class="btn">
            <van-button type="danger" size="large" @click="submit">提交</van-button>
        </div>
    </div>
</template>
<script>
import { mapState } from'vuex'
export default {
    data(){
        return{
            manager_username: ''
        }
    },
    computed: {
      ...mapState(['openid'])
    },
    methods:{
        submit() {
            if(!this.manager_username) {
                this.$toast('请输入加盟商用户名')
                return
            }

            this._submit()
        },
        async _submit(){
            let { data: { code, data } } = await this.$http.post(this.$api.platformCard,{
                manager_username: this.manager_username,
                openid: this.openid
            })
            if(code === 0) {
                this.$toast(data)
                this.getUserInfo()
            }
        },
        async getUserInfo() {
            let { data: { code, data } } = await this.$http.get(this.$api.userinfo,{
                    openid: this.openid
                }
            )
            if(code === 0) {
                localStorage.setItem('userState', data.userinfo.state)
                this.$store.commit('userState', localStorage.getItem('userState'))
                setTimeout(() => {
                    this.$router.go(-1)
                }, 1000)
            }
        }
    }
}
</script>
<style lang="scss" scoped>
    .content{
        .btn{
            margin: 1rem 0;
        }
    }
</style>